package FP;

import java.util.Arrays;
import java.util.stream.Stream;

public class FlatMapDemo {
    public static void main(String[] args) {
        Stream<String> stringStream1 = Stream.of("shi yan", "shi yan lou","lou yan shi");
        Stream<String> stringStream2 = Stream.of("shi yan", "shi yan lou","lou yan shi");
        // fold
        Stream<String[]> mapStream = stringStream1.map(v -> v.split(" "));
        System.out.println("map: ");
        mapStream.peek(System.out::println).count();
        // unfold
        System.out.println("flatMap: ");
        Stream<String> flatMapStream = stringStream2.flatMap(v -> Arrays.stream(v.split(" ")));
        flatMapStream.peek(System.out::println).count();
    }
}
